package jp.sourceforge.akjrcp.videotools.subtitlemaker;

import jp.sourceforge.akjrcp.ui.draw2d.CachedImageFigure;
import jp.sourceforge.akjrcp.ui.draw2d.CachedImageLoader;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.MarginBorder;
import org.eclipse.draw2d.Panel;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;

public class ThumbnailFigure extends Panel{
	Label titleLabel;

	CachedImageFigure imageLabel;
	CachedImageLoader loader;


	
	boolean selection;
	
	LineBorder lineBorder; 
	MarginBorder marginBorder;
	



	private int textHeight=16;
	 

	private int margin=2;
	private String filePath;
	private Object data;
	 public Dimension getPreferredSize(int wHint, int hHint) {
			Dimension d=new Dimension(imageLabel.getBounds().width +margin*2,imageLabel.getBounds().height +margin*2+textHeight );
			return d;
		}
	 
	public void setSelection(boolean bool){
		if(this.selection!=bool){
		this.selection=bool;
		if(selection){
			
			this.setBorder(lineBorder);
		}else{
			this.setBorder(marginBorder);
		}
		repaint();
		}
	}
	public boolean isSelection(){
		return selection;
	}
	public void turnSelection(){
		setSelection(!selection);
	}


	public String getLabel() {
		return titleLabel.getText();
	}

	public void setLabel(String text) {
		titleLabel.setText(text);
	}


	
	public ThumbnailFigure(String label, CachedImageLoader loader,int width,int height) {
	super();
    this.loader=loader;
    this.filePath=label;
	this.setLayoutManager(new XYLayout());
	imageLabel = new CachedImageFigure(loader,label,width,height);
	
	add(imageLabel,new Rectangle(0,0,width,height));
	titleLabel = new Label("");
	titleLabel.setLabelAlignment(PositionConstants.LEFT);
	
	titleLabel.setLocation(new Point(0,height));
	add(titleLabel,new Rectangle(0,height,width,textHeight));
	
	
	
	lineBorder = new LineBorder();
	lineBorder.setColor(ColorConstants.green);
	lineBorder.setWidth(margin);
	
	marginBorder=new MarginBorder(margin);
	this.setBorder(marginBorder);
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}


}
